<template>
  <div class="mod-tenant__tenant">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">

      <el-form-item>
        <el-input v-model="dataForm.categoryName" placeholder="档案类型名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.fileNumber" placeholder="档号" clearable></el-input>
      </el-form-item>
      <el-form-item>
      <el-select v-model="dataForm.useWay" placeholder="利用方式">
        <el-option :value="0" label="借阅">借阅</el-option>
        <el-option :value="1" label="浏览">浏览</el-option>
        <el-option :value="2" label="下载">下载</el-option>
        <el-option :value="3" label="打印">打印</el-option>
      </el-select>
      </el-form-item>
      <el-form-item>
      <div class="block">
        <span class="demonstration"></span>
        <el-date-picker
          v-model="valueD"
          @change="dateChange"
          type="datetimerange"
          range-separator="至"
          start-placeholder="归还开始日期"
          end-placeholder="归还结束日期">
        </el-date-picker>
      </div>

      </el-form-item>
      <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      <div style="width: 103%; height: 15px; background-color: rgb(240, 242, 245); margin: 0 -21px 15px"></div>
      <el-form-item>
        <el-button type="primary" @click="giveBack()">归还</el-button>
        <el-button type="primary" @click="addOrUpdateHandle()">新增利用申请</el-button>
      </el-form-item>
    </el-form>

    <el-table ref="multipleTable" stripe v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column label="租户名称" prop="tenantName" header-align="center" align="center"></el-table-column>
      <el-table-column label="档号" prop="fileNumber" header-align="center" align="center"></el-table-column>
      <el-table-column label="题名" prop="title" header-align="center" align="center"></el-table-column>
      <el-table-column label="档案类型" prop="categoryName" header-align="center" align="center"></el-table-column>
      <el-table-column label="利用方式" prop="useWay" header-align="center" align="center">
        <template v-slot="scope">
        <el-tag v-if="scope.row.useWay == 0" size="small" type="success">借阅</el-tag>
        <el-tag v-if="scope.row.useWay == 1" size="small" type="success">浏览</el-tag>
        <el-tag v-if="scope.row.useWay == 2" size="small" type="success">下载</el-tag>
        <el-tag v-if="scope.row.useWay == 3" size="small" type="success">打印</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="申请日期" prop="applyData" header-align="center" align="center"></el-table-column>
      <el-table-column label="预计归还日期" prop="predictData" header-align="center" align="center"></el-table-column>
      <el-table-column label="实际归还日期" prop="returnData" header-align="center" align="center"></el-table-column>
      <el-table-column label="申请人" prop="proposer" header-align="center" align="center"></el-table-column>
      <el-table-column label="利用组织" prop="useTenantName" header-align="center" align="center"></el-table-column>
      <el-table-column label="利用状态" prop="userState" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.userState == 0" size="small" type="danger">未归还</el-tag>
          <el-tag v-if="scope.row.userState == 1" size="small" type="success">已归还</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination style="padding: 0px 38%" :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <UsingRecordsAdd  v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></UsingRecordsAdd>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import baseService from "@/service/baseService";
import UsingRecordsAdd from "./using-records-add.vue";
export default defineComponent({
  components:{
    UsingRecordsAdd
  },
  setup() {
    const state = reactive({
      getDataListURL: "/archive/using-records/page",
      getDataListIsPage: true,
      valueD:"",
      dataForm: {
        id:"",
        predictDataBegin: "",
        predictDataEnd: "",
        fileNumber: "",
        categoryName:"",
        useWay:""
      }
    });

    return { ...useView(state), ...toRefs(state) };
  },
  methods: {
    dateChange(v){
      this.dataForm.predictDataBegin = v[0]
      this.dataForm.predictDataEnd = v[1]
    },
    giveBack(){
      console.log(this.dataListSelections)
      baseService.put(`/archive/using-records/give-back`,this.dataListSelections.map(item=>item.id)).then((res) => {
        console.log(res)
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.getDataList();
      });
    }
  }
});
</script>
